;
; defines types manipulation routines and types registration facility
;
; main entities are:
;
; 	get-type-info
; 	type-info
; 	add-primitive-type-mappings
;

(defparameter *primitive-type-mappings* (make-hash-table))

(defun get-type-info (type-sym)
  (let ((result (gethash type-sym *primitive-type-mappings*)))
    (unless result (error "type is not found in the mapping table"))
    result))

(defstruct (type-info
            (:constructor
             create-type-info (&key lang-name size)))
  lang-name
  size
  )

(defun add-primitive-type-mappings (mappings-list)
  (dolist (type-mapping mappings-list)
    (let ((sym-type (first type-mapping))
          (type-inst (eval (append (list 'create-type-info) (cdr type-mapping))))
          )
      (assert (symbolp sym-type))

      (if (gethash sym-type *primitive-type-mappings*)
          (error "the symbol is already mapped"))

      (setf (gethash sym-type *primitive-type-mappings*) type-inst)
      )))
